import 'package:flutter/material.dart';
import 'package:flutter_food/core/model/meal_model.dart';
import 'package:flutter_food/core/viewmodel/filter_view_model.dart';

class BaseViewModel extends ChangeNotifier {
  // 食品列表
  List<MealModel> _mealList = [];

  // 设置依赖的ViewModel
  FilterViewModel _filterViewModel;

  void updateFilterViewModel(FilterViewModel filterViewModel) {
    _filterViewModel = filterViewModel;
  }

  // 返回过滤后的列表
  List<MealModel> get meals {
    return _mealList.where((meal) {
      if (_filterViewModel.isGlutenFree && !meal.isGlutenFree) return false;
      if (_filterViewModel.isLactoseFree && !meal.isLactoseFree) return false;
      if (_filterViewModel.isVegan && !meal.isVegan) return false;
      if (_filterViewModel.isVegetarian && !meal.isVegetarian) return false;
      return true;
    }).toList();
  }

  // 获取未过滤的数据列表
  List<MealModel> get originMealList => _mealList;

  set mealList(List<MealModel> value) {
    _mealList = value;
    notifyListeners();
  }
}
